package initialize

import (
	"gitee.com/CICP/cpgin/global"

	"gorm.io/gorm"
)

func Gorm() *gorm.DB {
	switch global.CPGIN_CONFIG.System.DbType {
	case "mysql":
		global.CPGIN_ACTIVE_DBNAME = &global.CPGIN_CONFIG.Mysql.Dbname
		return GormMysql()
	case "pgsql":
		global.CPGIN_ACTIVE_DBNAME = &global.CPGIN_CONFIG.Pgsql.Dbname
		return GormPgSql()
	case "oracle":
		global.CPGIN_ACTIVE_DBNAME = &global.CPGIN_CONFIG.Oracle.Dbname
		return GormOracle()
	case "mssql":
		global.CPGIN_ACTIVE_DBNAME = &global.CPGIN_CONFIG.Mssql.Dbname
		return GormMssql()
	case "sqlite":
		global.CPGIN_ACTIVE_DBNAME = &global.CPGIN_CONFIG.Sqlite.Dbname
		return GormSqlite()
	default:
		global.CPGIN_ACTIVE_DBNAME = &global.CPGIN_CONFIG.Mysql.Dbname
		return GormMysql()
	}
}
